﻿using Newtonsoft.Json;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DtoFw.Interface;

namespace SceneEvidenceAPISDK
{
    public class Base
    {
        /// <summary>
        /// 获取路由
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        public string GetApiRouter(string action)
        {
            return (string)typeof(IUser).GetMethods().FirstOrDefault(x => x.Name == action)
                    .GetCustomAttributesData().FirstOrDefault().NamedArguments.FirstOrDefault().TypedValue.Value;
        }
        /// <summary>
        /// 获取路由,替换
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        public string GetApiRouter(string action,
             string newValue, string oldeValue = "{params}")
        {
            string url = (string)typeof(IUser).GetMethods().FirstOrDefault(x => x.Name == action)
                    .GetCustomAttributesData().FirstOrDefault().NamedArguments.FirstOrDefault().TypedValue.Value;
            return url.Replace(oldeValue, newValue);
        }
    }
}
